(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/script/Spikes.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, '85453Px4/1B0bj8OE2fIl95', 'Spikes', __filename);
// script/Spikes.js

'use strict';

/**
 * 地刺道具  地刺在拖场景的时候静态地刺命名spikes 动态地刺以“spikes_”up/down/left/right  命名
 */
cc.Class({
    extends: cc.Component,

    properties: {},

    onLoad: function onLoad() {
        var type = this.node.name.split('_')[1];
        this.limit = 30; //地刺的最大长度
        this.pos = 0;
        switch (type) {
            case 'up':
                this.distence = 2;
                this.dir = 'y';
                break;
            case 'down':
                this.distence = -2;
                this.dir = 'y';
                break;
            case 'left':
                this.distence = -2;
                this.dir = 'x';
                break;
            case 'right':
                this.distence = 2;
                this.dir = 'x';
                break;
            default:
                break;
        }
    },

    // 只在两个碰撞体开始接触时被调用一次
    onBeginContact: function onBeginContact(contact, selfCollider, otherCollider) {},

    update: function update(dt) {
        //地刺的移动和地刺移动到最大值时反向移动
        this.pos += this.distence;
        this.node[this.dir] += this.distence;
        if (Math.abs(this.pos) === this.limit) {
            this.distence *= -1;
        }
    }
});

cc._RF.pop();
        }
        if (CC_EDITOR) {
            __define(__module.exports, __require, __module);
        }
        else {
            cc.registerModuleFunc(__filename, function () {
                __define(__module.exports, __require, __module);
            });
        }
        })();
        //# sourceMappingURL=Spikes.js.map
        